import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import uploader from 'vue-simple-uploader'
import 'default-passive-events'

import { recoverState } from './utils/global'//引入全局函数，恢复states
import VueClipboard from 'vue-clipboard2'


Vue.config.productionTip = false
Vue.use(uploader)
Vue.use(VueClipboard)

const titles = {
  all: '全部文件',
  doc: '文档',
  pic: '图片',
  seed: '种子',
  video: '视频',
  music: '音乐',
  other: '其他',
  share: '我的分享',
  recycle: '回收站'
}
//路由守卫
router.beforeEach(async (to, from, next) => {
  //console.log(from,to)
  to.query.timestamp = new Date().getTime();
  //const isLogin = store.getters.getUserInfo;//获取store用户信息对象，用于判断是否登录
  //console.log(isLogin.userName);
  if (to.meta.title) {
    document.title = to.params.type ? titles[to.params.type] : to.meta.title
  }
  if (to.path === '/login') {//非登录状态 一律跳转login
    next()
  } else {
    if (to.path !== '/login') {
      await recoverState()
    }
    if (to.matched.length === 0) {
      next('/login')
    } else {
      next()
    }
    //} else {
    //  next('/login')
    //}
    // next()
  }

  // if (isLogin) {
  //   //登录状态 跳转路由是否存在 存在就跳转，否则跳到404
  //   if (to.matched.length === 0) {
  //     next('/404')
  //   } else {

  //     next()
  //   }
  // } else {
  //   if (to.path === '/login') {//非登录状态 一律跳转login
  //     next()
  //   } else {
  //     next('/login');
  //   }

  // }
});


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
